package dao.imp;

import dao.Userdao;
import domain.User;
import utils.JDBCutil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Userdaoimp implements Userdao {
    @Override
    public List<User> selectUser(User loginUser) throws SQLException {
       Connection con =JDBCutil.getCon();
       String sql="select * from lo where username=? and password=?";
        String[] strs={loginUser.getUsername(), loginUser.getPassword()};
        ResultSet rs =JDBCutil.excuteQuery(sql,strs);
       //        PreparedStatement p = con.prepareStatement(sql);
//        p.setString(1,loginUser.getUsername());
//        p.setString(2,loginUser.getPassword());
//        ResultSet rs=p.executeQuery();
        User user=null;
        List<User> us=new ArrayList<>();
        while(rs.next()){
            int id=rs.getInt("id");
            String username=rs.getString("Username");
            String password=rs.getString("password");
            /*从数据库取出来，封装到类里*/
            user=new User(id,username,password);
            /**/
            us.add(user);
        }
        return us;
    }
}
